<template>
  <div class="wrap" >
    <div class="title">
      <img src="../../images/main/server.png" alt> 服务商管理
    </div>
    <div class="screen">
      <img src="../../images/main/screen.png" alt> 筛选查询
    </div>
    <div class="sel">
      <div class="txt">关键词：</div>
      <input type="text" placeholder="服务商名称/手机号" v-model="params.keyWord">
      <div class="btn"  @click="getServerList()" style="cursor: pointer;">搜索</div>
    </div>
    <div class="clear"></div>
    <div class="table">
      <div class="thead">服务商列表
        <div v-if="roleList.indexOf('增加服务商') != '-1'" class="addpar" @click="addServer()">
          <img class="add" src="../../images/main/add.png" alt> 增加服务商
        </div>
      </div>
      <div class="sthead">
        <div class="parname">logo</div>
        <div class="parnum">服务商名称</div>
        <div class="phone">服务类别</div>
        <div class="area">服务商账号</div>
        <div class="monkey">平台佣金</div>
        <div class="date">服务区域</div>
        <div class="update">更新时间</div>
        <div class="state">当前状态</div>
        <div class="ctrl lastlist">操作</div>
      </div>
      <div class="tlists">
        <div class="tlist" v-for="(item,index) in serverList" :key="index">
          <div class="parname">
            <img class="tlogo" :src="item.service_logo!='' ? item.service_logo : serverDefaultLogo" alt>
          </div>
          <div class="parnum">{{item.service_name|| '-' }}</div>
          <div class="phone">{{item.service_type|| '-'}}</div>
          <div class="area">{{item.service_account|| '-'}}</div>
          <div class="monkey">{{item.commission == 0  ?'-' : item.commission + '%'}}</div>
          <div class="date">{{item.region || '-'}}</div>
          <div class="update">
            <div class="day">{{setDate(item.time)}}</div>
            &nbsp;
            <div class="time">{{setTime(item.time)}}</div>
          </div>
          <div class="state">{{(item.states == 0) ? '正常' : '冻结中'}}</div>
          <div class="ctrl lastlist">
            <ul>
              <li v-if="roleList.indexOf('分佣设置') != '-1' && roleList.indexOf('服务商管理') != '-1'" class="firli" @click="subCommission(item.id)">分佣设置</li>
              <li v-if="roleList.indexOf('编辑服务商') != '-1'"  class="firli" @click="editParMan(item.id)">编辑</li>
              <li v-if="roleList.indexOf('编辑服务商') != '-1'" @click="resetPwd( item.id )">重置密码</li>
              <li v-if="roleList.indexOf('服务商管理') != '-1'" @click="serverDeatil(item.id)">详情</li>
              <li v-if="roleList.indexOf('收款账号') != '-1'" @click="reaccServer(item.id)">收款账号</li>
              <li v-if="roleList.indexOf('冻结/解除冻结') != '-1' && roleList.indexOf('服务商管理') != '-1'" @click="setFrozen(item.states,item.id)"> {{item.states == 0  ? '冻结' : '解除冻结'}}</li>
            </ul>
          </div>
        </div>
        <el-pagination
          class="pagination-box"
          background
          layout="prev, pager, next"
          :total="pageTotal"
          @current-change="changePage">
        </el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import Global from '../tool/Global.vue'
import axios from 'axios'
import qs from 'qs' // 将请求转换成form 表单提交形式
import serverDefaultLogo from'@/images/main/server-logo.png'
export default {
  data() {
    return {
      loading: false,
      pageTotal: 1,
      params: {
        page: 1,
        limit: 10,
        keyWord: ""
      },
      serverList:[],
      roleList:'',
      serverDefaultLogo: serverDefaultLogo
    };
  },
  methods: {
    /**
     *  获取权限
     */
    getRole: function () {

      let that = this;
      axios({
          method: 'post',
          url:`${that.$store.state.url}/sysPermission/selectByEmployeeId`,
            data:qs.stringify({
              empId:that.$cookie.get('pid')
            })
      }).then(res => {
            console.log(res)
            let arr = res.data.data
            let role = []
            for(let i = 0; i < arr.length; i++) {
              role.push(arr[i].name)
            }
            this.roleList = role.toString()
        });
    },
    // 分页
    changePage( page ) {
      console.log(page)
      this.params.page = page;
      this.getServerList();
    },
    // 重置密码
    resetPwd( id ) {
      // this.$prompt(
      //   '输入新密码', '提示', {
      //   confirmButtonText: '确定',
      //   cancelButtonText: '取消'
      // }).then(({ value }) => {
      //   axios.post (
      //     `${this.$store.state.url}/tService/updatePwd`,
      //     qs.stringify({
      //       id: id,
      //       pwd: value
      //     })
      //   ).then ( response => {
      //     this.$alert ( response.data.msg );
      //   });
      // }).catch(() => {

      // });
      this.$confirm ( '确认重置密码?' ).then (() => {
        axios.post (
          `${this.$store.state.url}/tService/updatePwd`,
          qs.stringify({
            id: id,
          })
        ).then ( response => {
          // this.$alert ( response.data.msg );
          this.$store.state.fn.success( response.data.msg );
        });
      });
    },
    // 服务商编辑
    editParMan( id ) {
      this.$router.push ({
        path: '/main/editServer',
        query: {
          id: id
        },
        name:'editServer'
      });
    },
    /**
     * 获取服务商列表
     */
    getServerList: function() {
      this.loading = true;
      let that = this;
      axios({
          method: 'post',
          url:`${that.$store.state.url}/tService/getServiceList`,
            data:qs.stringify(that.params)
      }).then(res => {
            console.log(res)
          this.loading = false;
          if (res.data.code == 0) {
            that.serverList = res.data.data
            that.pageTotal = res.data.count
          } else {
            this.$alert(res.msg);
          }
        });
    },
    addServer: function() {
      this.$router.push({
        path: "addServer",
        name: "addServer"
      });
    },
    /**
     * 分佣设置
     */
    subCommission: function(id) {
      Global.serverId = id
      this.$router.push({
        path: "/main/server-subCommission"
      });
    },
    /**
     * 账户信息
     */
    reaccServer: function(id) {
      Global.serverId = id
      console.log(id)
      this.$router.push({
        path: "reaccServer",
        query: {
          id: id
        }
      });
    },
    // 详情
    serverDeatil: function(id) {
      Global.serverId = id
      console.log(id)
      this.$router.push({
        path: "serverDeatils"
      });
    },
    /**
     * 冻结 解冻
     */
    setFrozen: function (states,id) {

      let that = this;
      if (states == 0) {
        states = 1
      } else {
        states = 0
      }
      this.$confirm ( states == 0 ? '是否取消冻结？' : '是否确认冻结？' ).then (() => {
        let data = {
          states:states,
          id:id
        }
        axios({
            method: 'post',
            url:`${that.$store.state.url}/tService/updateStates`,
              data:qs.stringify(data)
        }).then(res => {
          if (res.data.code == 0) {
            this.$store.state.fn.success( states == 0 ? '解除冻结成功' : '确认冻结成功' ).then (() => {
              that.getServerList()
            });
          } else {
            alert(res.msg);
          }
        });
      });
    },
    /**
     * 根据时间毫秒数 返回年月日
     */
    setDate: function (str) {
        // let times = new Date(str)
        // return `${times.getFullYear()}-${times.getMonth() + 1 < 10 ? '0' + times.getMonth() + 1 : times.getMonth() + 1}-${times.getDate() < 10 ? '0' + times.getDate() : times.getDate()}`
        return this.$moment(str).format('YYYY-MM-DD')
    },
    /**
     * 根据时间毫秒数 返回时分秒
     */
    setTime: function (str) {
        // let times = new Date(str)
        // return `${times.getHours() < 10 ? '0' + times.getHours() : times.getHours()}:${times.getMinutes() < 10 ? '0' + times.getMinutes() : times.getMinutes()}:${times.getSeconds() < 10 ? '0' + times.getSeconds() : times.getSeconds()}`
        return this.$moment(str).format('hh:mm:ss')
    }
  },
  mounted () {
    this.getServerList()
    this.getRole()
  }
};
</script>
<style scoped>
.wrap {
  /* padding: 68px 136px; */
  /* width: 100%; */
  width: 90%;
  margin: 40px auto;
}
.title {
  height: 33px;
  line-height: 33px;
  font-size: 24px;
  font-family: PingFangSC-Medium;
  font-weight: bold;
}
.title img {
  width: 28px;
  height: 26px;
  float: left;
  padding-top: 5px;
  margin-right: 10px;
}
.parname .tlogo {
  width: 90px;
  height: 90px;
}
.screen {
  /* width: 1490px; */
  height: 60px;
  background: #f6f6f6;
  /* margin-left: 38px; */
  margin-top: 24px;
  line-height: 60px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
}
.screen img {
  float: left;
  width: 27px;
  height: 27px;
  margin-left: 10px;
  margin-top: 16px;
  margin-right: 18px;
}
.sel {
  margin-top: 27px;
  /* padding-left: 38px; */
  height: 40px;
  line-height: 40px;
}
.sel .txt {
  float: left;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #000000;
  font-weight: bold;
  width: 73px;
}
.sel input {
  float: left;
  background: #ffffff;
  box-shadow: inset 0 1px 3px 0 rgba(0, 0, 0, 0.5);
  width: 317px;
  height: 40px;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #888888;
  margin-left: 17px;
  text-align: center;
  box-sizing: border-box;
}
.btn {
  float: left;
  color: #fff;
  background: #085dab;
  border: 1px solid #085dab;
  width: 140px;
  height: 38px;
  text-align: center;
  margin-left: 37px;
}
.table {
  /* width: 1490px; */
  margin-top: 43px;
  /* margin-left: 38px; */
}
.table .sthead {
  border-bottom: 1px solid #dddddd;
  height: 67px;
  font-family: PingFangSC-Medium;
  font-size: 20px;
  color: #000000;
  line-height: 67px;
  font-weight: bold;
  background: #e0eefe;
}
.parname {
  /* width: 187px; */
  width: 10%;
  text-align: center;
}
.parname img {
  /* margin: 18px 0 0 9px; */
  /* width: 170px; */
  height: 90px;
  /* float: left; */
  width:auto;
  max-width: 170px;
  vertical-align: middle;
}
.sthead > div {
  float: left;
  border-left: 1px solid #ddd;
  text-align: center;
  box-sizing: border-box;
}
.parnum {
  /* width: 149px; */
  width: 10%;
}
.phone {
  /* width: 162px; */
  width: 10%;
}
.area {
  /* width: 137px; */
  width: 10%;
}
.monkey {
  /* width: 147px; */
  width: 10%;
}
.date {
  /* width: 140px; */
  width: 10%;
}
.update {
  /* width: 184px; */
  width: 15%;
}
.state {
  /* width: 142px; */
  width: 10%;
}
.table .thead {
  text-align: left;
  font-family: PingFangSC-Medium;
  font-size: 24px;
  color: #000000;
  height: 69px;
  line-height: 69px;
  padding-left: 15px;
  background: #e0eefe;
  border: 1px solid #dddddd;
  box-sizing: border-box;
  font-weight: bold;
}
.addpar {
  background: #f6f6f6;
  border: 1px solid #085dab;
  border-radius: 2px;
  /* width: 107px; */
  height: 33px;
  float: right;
  font-family: PingFangSC-Regular;
  font-size: 14px;
  line-height: 33px;
  margin-top: 17px;
  margin-right: 20px;
  color: #085dab;
  cursor: pointer;
  padding: 0 5px;
}
.add {
  width: 18px;
  height: 18px;
  float: left;
  margin: 8px;
}
.tlist > div {
  height: 142px;
  word-break: break-all;
  display: flex;
  -webkit-box-align: center;
  -ms-flex-align: center;
  align-items: center;
  -webkit-box-pack: center;
  -ms-flex-pack: center;
  justify-content: center;
}
.tlist .update {
  line-height: 25px;
  /* padding-top: 43px; */
  height: 142px;
}
.day,
.time {
  height: 25px;
  line-height: 25px;
}
.ctrl {
  /* width: 242px; */
  width: 15%;
}
.tlist {
  height: 142px;
  /*line-height: 142px;*/
}
.lastlist {
  border-right: 1px solid #ddd;
}
.tlist > div {
  float: left;
  text-align: center;
  border-left: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  box-sizing: border-box;
}
.tlist:last-of-type {
  border-bottom: 1px solid #ddd;
}
.ctrl ul {
  overflow: hidden;
  margin-top:18px;
  width: 98%;
  margin-left: 2%;
  /* width: 179px; */
  /* padding: 18px 19px 20px 31px; */
  /* height: 104px; */
}
.ctrl ul li {
  float: left;
  /* width: 72px; */
  width: 50%;
  height: 25px;
  line-height: 25px;
  text-align: center;
  font-family: PingFangSC-Medium;
  font-size: 18px;
  color: #085dab;
  margin-top: 15px;
  font-weight: bold;
  cursor: pointer;
}
.ctrl ul li:nth-of-type(2n) {
  /* margin-left: 35px; */
}
.ctrl .firli {
  margin-top: 0px;
}
.clear {
  clear: both;
}
.pagination-box{
  text-align: center;
  padding: 40px;
}
</style>
<style>
.el-pagination.is-background .el-pager li:not(.disabled):hover{
    background-color:#085dab;
    color: #d2e0ef;
}
.el-pagination.is-background .el-pager li:not(.disabled).active{
  background-color:#085dab;
}
</style>

